package com.qiahao.mapper;

import com.qiahao.bean.User;
import com.qiahao.dto.UserDto;
import org.apache.ibatis.annotations.*;

/**
 * Created by Administrator on 2018/4/2 0002.
 */
public interface UserMapper {

    @Select("select * from sys_user a where a.username = #{username} limit 1")
    @Results({
            @Result(property = "role",column = "role_id",one = @One(select = "com.qiahao.mapper.RoleMapper.findRoleById"))
    })
    UserDto findByUsername(String username);


    @Select("select * from sys_user a where a.id = #{userId}")
    UserDto findByUserById(Long userId);


    @Insert("insert into sys_user (username,password,role_id) values (#{username},#{password},#{roleId})")
    void addUser(User user);

    @Update("<script> update sys_user set " +
            " <if test=\"password != null\">password=#{password}</if> " +
            " <if test=\"username != null\">username=#{username}</if> " +
            "</script>"
    )
    void  updateUser(User user);

}
